﻿using BCCServer.DAO.Interfaces;
using BCCServer.IService.IChatService;
using BCCServer.IService.ILoginService;
using BCCServer.Model.Models;
using BCCServer.Model.ModelsOut;
using BCCServer.Web.Filter;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Principal;

namespace BCCServer.Web.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CommodityController : ControllerBase
    {
        private readonly ICommodity icommodity;

        public CommodityController(ICommodity commodity)
        {
            this.icommodity = commodity;
        }

        [HttpGet]
        [Route("selCommodityAsync")]
        //[ManagerAuthorize]
        public async Task<BaseOut> selCommodityAsync(int pageNumber = 1, int pageSize = 20)
        {
            try
            {
                var rs = await icommodity.selCommodityAsync(pageNumber, pageSize);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }

        /// <summary>
        /// 减少库存
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("selCommodityAsync")]
        //[ManagerAuthorize]
        public BaseOut reduceCommodity(int Id)
        {
            try
            {
                var rs = icommodity.reduceCommodity(Id);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }

        [HttpPost]
        [Route("addShoppingcart")]
        //[ManagerAuthorize]
        public  BaseOut addShoppingcart(SShoppingcartInput shoppingcart)
        {
            try
            {
                var rs =  icommodity.addShoppingcart(shoppingcart);
                return new BaseOut { code = "true", content = rs };
            }
            catch (Exception)
            {
                return new BaseOut { code = "false", content = "查询失败" };
            }
        }
    }
}
